/*
 * @Description:封装axios请求方法
 * @Author: HYH
 * @LastEditors: HYH
 * @LastEditTime: 2022-08-22 16:53:54
 */
import { AxiosRequestConfig } from 'axios'
import instance from './instance'
/**get方法 */
const get = (url: string, config?: AxiosRequestConfig) => {
  return new Promise((resolve, reject) => {
    instance
      .get(url, config)
      .then(res => resolve(res.data))
      .catch(err => reject(err))
  })
}
/**post方法 */
const post = (url: string, params?: any, config?: AxiosRequestConfig) => {
  return new Promise((resolve, reject) => {
    instance
      .post(url, params, config)
      .then(res => resolve(res.data))
      .catch(err => reject(err))
  })
}
/**上传方法 */
const upload = (url: string, params: any, config?: AxiosRequestConfig) => {
  return new Promise((resolve, reject) => {
    instance
      .post(url, params, config)
      .then(res => resolve(res.data))
      .catch(err => reject(err))
  })
}
const http = {
  /**get方法 */
  get,
  /**post方法 */
  post,
  /**上传方法 */
  upload
}
export type IHttp = typeof http
export default http
